我有一个String数组,我想使用Java 8流将其转换为BigInteger数组。
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Manage Permissions <?php echo $a=$_REQUEST['user_id'];?></h4>
</div>
<div class="modal-body">
<div class="row">
<form action="" method="POST">
<?php include 'permissions.php';?>
<!-- END TABLE STRIPED -->
<div class="container-fluid">
<button type="submit" class="btn btn-primary" name="btn_user_permissions">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
这是我尝试的但是我无法获得BigInteger数组,但是我能够获得Object数组。
String[] output = bigSorting(new String[]{"31415926535897932384626433832795", "1", "4900146572543628830293235422623540449026979", "10", "57500297590012603652986133599394871645776460", "5",
"497010206818067722087306230802257700034825862515267073569769100385728461314", "57500297590012603652986133599394871645776460497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314"});
Object[] unsortedBigIntegerArr = convertFromStringArrayToBigIntegerArray(output);
我有什么方法可以完全使用Java 8流。
答案 0 :(得分:4)
简单如下:
return Arrays.stream(unsorted)
.map(BigSorting2::convertFromStringToBigInteger)
.toArray(BigInteger[]::new);
答案 1 :(得分:0)
非常简单的事情:
public void test(String[] args) {
String[] output = new String[]{"31415926535897932384626433832795", "1", "4900146572543628830293235422623540449026979", "10", "57500297590012603652986133599394871645776460", "5",
"497010206818067722087306230802257700034825862515267073569769100385728461314", "57500297590012603652986133599394871645776460497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314497010206818067722087306230802257700034825862515267073569769100385728461314"};
Object[] bigIntegers = Arrays.stream(output)
.map(BigInteger::new)
.toArray();
System.out.println(Arrays.toString(bigIntegers));
}